const Servers = require('../lib/server');
const sql = new Servers('uu_feedback');
const search = require('../lib/search');
const mysql = require('../lib/mysql');
const util = require('../lib/util');
class Feedback {
  // 提交反馈信息
  static async submit(data) {
    return await sql.insert(data);
  }
  // 列表
  static async list(data) {
    let sqlinfo = 'SELECT * FROM uu_feedback';
    if (data) {
      let info = Object.assign({}, data);
      sqlinfo += util.handleQuest(info);
    }
    return await mysql.sql(sqlinfo, {}, 'select');
  }
  // 列表带分页
  static async listCount(data) {
    let sqlinfo = 'SELECT * FROM uu_feedback',
      countSql = 'SELECT COUNT(*) total FROM uu_feedback';
    search(data, sqlinfo, ['name', 'device']);
    countSql += data.wtxt + data.sqlTxt;
    let [list, count] = await Promise.all([
      mysql.sql(data.selectSql, {}, 'select'),
      mysql.sql(countSql, {}, 'select')
    ]);
    list.total = count.data[0].total;
    return Promise.resolve(list);
  }
}
module.exports = Feedback;